#import <Foundation/Foundation.h>
#import <objc/runtime.h>
#import <UIKit/UIApplication.h>
#import <SpringBoard/SBApplicationController.h>
#import <SpringBoard/SBApplication.h>
#import "PIDotView.h"

static NSString* dotshine;

@implementation PIDotView

@synthesize color;

-(void) drawRect:(CGRect) rect
{
	CGContextRef ctx = UIGraphicsGetCurrentContext();
	[self.color set];
	
	if (dotshine == nil) {
		NSBundle* b = [NSBundle bundleWithPath:@"/System/Library/Frameworks/EventKitUI.framework"]; // For iOS 4.X
		if (b == nil)
			b = [NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/CalendarUI.framework"]; // For iOS 3.X
		
		NSString* path = [b pathForResource:@"dotshine" ofType:@"png"];
		[path retain]; // Avoid a weak reference as we aren't using an accessor
		dotshine = path;
	}
	
	if (dotshine != nil) {
		UIImage* image = [UIImage imageWithContentsOfFile:dotshine];
		
		if (image != nil) {
			CGContextFillEllipseInRect(ctx, rect);
			[image drawInRect:rect];
		}
	}
}

@end
